
#region Imported Namespaces
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Tracer = PHSRAG.Utility.Tracer;
using SSO = PHSRAG.Security.SSO;
#endregion

namespace WebApp_CS
{
	public class Page1 : System.Web.UI.Page
	{
		#region Constants
		private const string LoginCommand = "Login";
		private const string LogoutCommand = "Logout";
		#endregion

		#region Instance Variables (Protected)
		protected Button					getLogin;
		protected Button					login;
		protected TextBox					loginID;
		protected RequiredFieldValidator	loginIDValidator;
		#endregion

		#region Instance Variables (Private)
		private SSO sso = new SSO();
		#endregion

		#region Event Handlers
		private void OnGetLogin(object sender, EventArgs e)
		{
			string user = sso.GetLogin(string.Empty);
			if (user == null)
			{
				login.Text = LoginCommand;
				loginID.Text = string.Empty;
			}
			else
			{
				login.Text = LogoutCommand;
				loginID.Text = user;
			}

			loginIDValidator.Enabled = loginID.Visible = login.Visible = true;
		}

		private void OnLogin(object sender, EventArgs e)
		{
			if (login.Text == LoginCommand)
			{
				sso.Enter(string.Empty, loginID.Text);
				login.Text = LogoutCommand;
			}
			else
			{
				sso.Leave(string.Empty, loginID.Text);
				Session.Abandon();
				login.Text = LoginCommand;
			}
		}

		private void OnPageLoad(object sender, System.EventArgs e)
		{
			Tracer.Trace(string.Format("OnPageLoad: {0}", IsPostBack));
		}
		#endregion

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.getLogin.Click += new System.EventHandler(this.OnGetLogin);
			this.login.Click += new System.EventHandler(this.OnLogin);
			this.Load += new System.EventHandler(this.OnPageLoad);

		}
		#endregion
	}
}

// --- EOF ---
